package com.thebox.config;

import java.util.*;

import linuxbox.util.BoxAdminModule;
import linuxbox.BoxStatic;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2002</p>
 * <p>Company: </p>
 * @author unascribed
 * @version 1.0
 */

public class AdminModule
{
  public String name;
  public String url;
  public String urlType;
  public long accessRights;

  public AdminModule()
  {
  }

  public String getName()
  {
    return name;
  }

  public String getUrl()
  {
    return url;
  }

  public String getUrlType()
  {
    return urlType;
  }

  public long getAccessRights()
  {
    return accessRights;
  }

  public void setModule(String n, String u, String t, String ar)
  {
    name = n;
    url = u;
    urlType = t;

    long lRights = 0;
    StringTokenizer s = new StringTokenizer(ar, ",");
    while (s.hasMoreTokens())
    {
      long l = Long.parseLong(s.nextToken().trim(), 16);
      lRights |= l;
    }
    accessRights = lRights;
  }

  public BoxAdminModule getBoxAdminModule()
  {
    String newUrl = url;
    if (urlType != null)
    {
      if (urlType.compareTo("jsp") == 0)
      {
        newUrl = BoxStatic.jspDir + url;
      }
      else if (urlType.compareTo("servlet") == 0)
      {
        newUrl = BoxStatic.servletDir + url;
      }
    }

    return new BoxAdminModule(name, newUrl, accessRights);
  }

  public String toString()
  {
    String newline = System.getProperty("line.separator");
    StringBuffer buf = new StringBuffer();

    buf.append("AdminModule - ").append(newline);
    buf.append("\tName=").append(name).append(newline);
    buf.append("\tUrl=").append(url).append(newline);
    buf.append("\tUrlType=").append(urlType).append(newline);
    buf.append("\tAccessRights=").append(accessRights).append(newline);

    return buf.toString();
  }

  public static void debug(Object obj)
  {
    System.out.println("From AdminModule: " + obj);
  }
}
